home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / 1svga.zip / PART.PAS < prev    next >
Pascal/Delphi Source File  |  1994-04-27  |  1KB  |  42 lines

  1. { Write part of a file }
  2.  
  3. uses Txt; {$I+}
  4.  
  5. { ─────────────── Part ─────────────── }
  6. procedure Part(Filename1,Filename2:string;Start,Len,Start2:longint);
  7. var File1,File2:file;
  8.     I,N,Q:longint;
  9.     Buf:pointer;
  10. begin
  11.   GetMem(Buf,64000);
  12.   Assign(File1,Filename1); Reset(File1,1);
  13.   Assign(File2,Filename2); {$I-} Reset(File2,1); {$I+}
  14.   if IOResult<>0 then Rewrite(File2,1);
  15.   Seek(File1,Start); Seek(File2,Start2);
  16.   N:=64000; Q:=Len div 64000;
  17.   for I:=0 to Q do begin
  18.     if I=Q then N:=Len mod 64000;
  19.     BlockRead(File1,Buf^,N);
  20.     BlockWrite(File2,Buf^,N);
  21.   end;
  22.   Close(File1); Close(File2);
  23.   FreeMem(Buf,64000);
  24. end;
  25.  
  26. var A,B,C,L:longint;
  27.     I:integer;
  28. begin
  29.   Writeln;
  30.   Writeln('Part ─── Write part of a file');
  31.   Writeln('Copyright (C) 1994 by Jou-Nan Chen');
  32.   L:=FileLen(ParamStr(1),1);
  33.   Val(ParamStr(3),A,I); Val(ParamStr(4),B,I); Val(ParamStr(5),C,I);
  34.   if (ParamCount<>5) or (I<>0) or (L<1) or (A<0) or (B<1) or (C<0)
  35.   or (A>L-1) or (B>L-A) then begin
  36.     Writeln;
  37.     Writeln('Usage: Part InputFile OutputFile StartByte Length File2StartByte');
  38.     Halt(1);
  39.   end;
  40.   Part(ParamStr(1),ParamStr(2),A,B,C);
  41. end.
  42.